/*
 * @Date: 2025-07-15 10:33:06
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-08-04 10:59:27
 * @FilePath: \corpus\src\components\Dept\index.tsx
 */
import { useModel } from '@umijs/max';
import { useMemo } from 'react';
import HeaderDropdown from '../HeaderDropdown';

const Dept = () => {
  const { initialState } = useModel('@@initialState');
  const { currentUser } = initialState || {};
  const { changeDeptCode } = useModel('useUser', (model) => ({
    changeDeptCode: model.changeDeptCode,
  }));
  const deptList: any = useMemo(() => {
    let arr: any = [];
    arr = currentUser?.deptList.map((item) => {
      return { ...item, key: item.deptCode, label: item.deptName };
    });
    return arr;
  }, [currentUser]);

  return (
    <>
      <HeaderDropdown
        menu={{
          selectedKeys: [currentUser?.deptCode as string],
          onClick: (val) => {
            changeDeptCode(val.key);
          },
          items: deptList,
        }}
      >
        <span
          style={{
            height: '48.0px',
            lineHeight: '40.0px',
            fontSize: '14.0px',
            marginLeft: '16.0px',
          }}
        >
          {currentUser?.deptName}
        </span>
      </HeaderDropdown>
    </>
  );
};
export default Dept;
